package com.example.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.entity.PsLineInfo;
import com.example.service.PsLineInfoService;
import com.example.vo.PsLineInfoVo;
import com.example.vo.PsPoleInfoVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yt
 * @since 2024-04-22
 */
@RestController
@RequestMapping("/psLineInfo")
@RequiredArgsConstructor
@CrossOrigin
public class PsLineInfoController {
    private final PsLineInfoService psLineInfoService;

    /**
     * 分页查询
     *
     * @return
     */
    @RequestMapping(value = "/psLineInfoPage", method = RequestMethod.GET)
    public Result psLineInfoList(PsLineInfoVo vo) {
        Page<PsLineInfo> page = new Page<PsLineInfo>(vo.getPageNum(), vo.getPageSize());
        IPage<PsLineInfo> bySearch = psLineInfoService.findBySearch(page, vo);
        return Result.success(bySearch);
    }


    @RequestMapping(value = "/updateIsStart", method = RequestMethod.POST)
    public Result updateIsStart(@RequestBody Map<String, Object> map) {
        PsLineInfo psLineInfo = new PsLineInfo();
        psLineInfo.setId((Integer) map.get("id"));
        psLineInfo.setIsstart((Integer) map.get("isstart"));
        psLineInfoService.updateIsStart(psLineInfo);
        return Result.success();
    }

    /**
     * 添加线路
     *
     * @param psLineInfo
     * @return
     */
    @RequestMapping(value = "/addPsLineInfo", method = RequestMethod.POST)
    public Result addPsLineInfo(@RequestBody PsLineInfo psLineInfo) {
        if (psLineInfo.getId() == null) {
            psLineInfoService.addPsLineInfo(psLineInfo);
        } else {
            psLineInfoService.updatePsLineInfo(psLineInfo);
        }
        return Result.success();
    }

    /**
     * 删除线路
     */
    @RequestMapping(value = "/delPsLineInfo", method = RequestMethod.GET)
    public Result delPsLineInfo(Integer id) {
        psLineInfoService.delete(id);
        return Result.success();
    }

    @RequestMapping(value = "/runningStatus", method = RequestMethod.GET)
    public Result down() {
        List<PsLineInfo> psLineInfos = psLineInfoService.down();
        return Result.success(psLineInfos);
    }

    @RequestMapping("listpli")
    public List<PsLineInfo> listpli(){

        return psLineInfoService.listpli();
    }


}
